<template>
	<view class="card" :style="{width:cardWidth*2+'rpx',height:cardHeight*2+'rpx'}" @click="click">
		<view class="card-image" :style="{height:cardWidth*2+'rpx'}">
			<image :src="this.$urlPrefix+goods.mainImages[0]" mode="scaleToFill"></image>
		</view>
		<view class="card-content">
			<view class="card-title">{{goods.title}}</view>
			<view class="card-buy-number_bar">
				已售{{goods.sale_num}}份
			</view>
			<view class="card-price_bar">
				<text class="price-number">{{goods.price}}</text>
				<text class="small-text" style="color: red">¥</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			goods: {
				type: Object,
				default () {
					return {

					}
				}
			}
		},
		data() {
			return {
				cardWidth: 187,
				cardHeight: 249,
				textLine: 2
			};
		},
		async created() {
			await this.$getSystemInfo().then(res => {
				this.cardWidth = res.screenWidth / 2 - 11
				this.cardHeight = (this.cardWidth / 3) * 4.4
				this.textLine = parseInt((this.cardHeight - this.cardWidth) / 20) - 2
				//console.log(this.textLine);
			})
		},
		methods: {
			click() {
				var id = this.goods.id
				uni.navigateTo({
					url: "/pages/goods-detail/goods-detail?id="+id,
				})
			}
		}
	}
</script>

<style lang="scss">
	.small-text {
		font-size: 24rpx;
		position: relative;
		top: 8rpx;
	}

	.card {
		//border: 2rpx red solid;	
		height: 500rpx;
		margin: 10rpx;
		border-radius: 10rpx 10rpx 0 0;
		box-shadow: 4rpx 10rpx 20rpx #ccc;
		box-sizing: border-box;
		overflow: hidden;

		.card-image {
			width: 100%;
			border-radius: 10rpx 10rpx 0rpx 0rpx;
			overflow: hidden;
		}

		.card-content {

			.card-title {
				font-size: 32rpx;
				margin: 10rpx;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				text-overflow: ellipsis;
				overflow: hidden;
				display: -webkit-box;
			}

			.card-buy-number_bar {
				display: flex;
				flex-direction: row;
				position: absolute;
				bottom: 20rpx;
				left: 20rpx;
				font-size: 24rpx;
				color: #999999;
			}

			.card-price_bar {
				//border: 2rpx blue solid;
				display: flex;
				flex-direction: row;
				position: absolute;
				bottom: 20rpx;
				right: 20rpx;

				.price-number {
					color: red;
					font-size: 32rpx;
					font-weight: bold;
					margin-right: 6rpx;
				}
			}
		}
	}
</style>
